<template>
  <section>
    <el-row>
      <el-card>
        <el-col :span="24">
          <el-select v-model="value">
            <el-option
              v-for="item in myColumnList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option
          ></el-select>
        </el-col>
        <el-col :span="24">
          <div style="margin: 20px  0;float: right">
            <el-button type="primary" @click="copyColumn()">确定 </el-button>
            <el-button @click="fail()">返回</el-button>
          </div>
        </el-col>
      </el-card>
    </el-row>
  </section>
</template>

<script>
// 复制文章
import { mapGetters } from "vuex";

export default {
  name: "copyArticle",
  computed: {
    ...mapGetters({
      myColumnList: "myColumnList",
      articleList: "articleList"
    })
  },
  props: {
    ids: {}
  },
  data() {
    return {
      value: "",
      columnTree: []
    };
  },
  mounted() {
    this.getColumnTree();
  },
  methods: {
    getColumnTree() {
      this.$store.dispatch("getMyColumnList").then(ret => {
        console.log(ret.data);
      });
    },
    // 复制文章
    async copyColumn() {
      let param = this.value;
      if (param == "") {
        this.warning("请选择栏目");
        return;
      }
      // 0不删除 1删除
      let type = 1;
      let confirm = await this.confirmForm({
        title: "是否删除原文章",
        cancelText: "不删除",
        confirmText: "删除"
      });
      if (confirm == "cancel") {
        type = 0;
      }
      let articleId = [];
      this.ids.map(item => {
        articleId.push(item.id);
      });
      let tem = {
        body: {
          articleId,
          itemId: this.ids[0].itemId,
          type,
          newItemId: param
        }
      };
      console.log("tem", tem);
      this.API.copyArticle(tem).then(() => {
        this.success("操作成功");
        this.value = "";
        this.$emit("close");
      });
    },
    fail() {
      this.$emit("close");
      this.value = "";
    }
  }
};
</script>

<style scoped>
/deep/.el-card__body {
  padding: 20px !important;
}
</style>
